package net.neptech.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import net.neptech.model.dto.InstanceDto;
import net.neptech.model.dto.InstanceParamDto;
import net.neptech.model.dto.PageResultDto;
import net.neptech.model.dto.TaskDto;
import net.neptech.model.vo.DataQueryVO;
import net.neptech.model.vo.InstanceCopyVo;
import net.neptech.model.vo.InstanceRecordVO;
import net.neptech.service.InstanceService;
import net.neptech.service.InstanceUserCopyService;
import net.neptech.vm.ResponseResult;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 流程实例接口
 */
@RestController
@RequestMapping("process-instance")
@RequiredArgsConstructor
public class InstanceController {
    private final InstanceService instanceService;
    private final InstanceUserCopyService instanceUserCopyService;


    /**
     * 启动流程
     */
    @SneakyThrows
    @PostMapping("startProcessInstance")
    public ResponseResult<String> startProcessInstance(@RequestBody InstanceParamDto instanceParamDto) {

        return ResponseResult.success(instanceService.startInstance(instanceParamDto));

    }


    /**
     * 查询当前登录用户已办任务的流程实例
     */
    @SneakyThrows
    @PostMapping("queryMineDoneProcessInstance")
    public ResponseResult<PageResultDto<InstanceDto>> queryMineDoneProcessInstance(@RequestBody DataQueryVO pageDto) {
        return ResponseResult.success(instanceService.queryMineDoneWorkflowInstance(pageDto))   ;
    }


    /**
     * 发起的流程列表
     */
    @PostMapping("queryList")
    public ResponseResult<Page> queryList(@RequestBody DataQueryVO pageDto) {
        return ResponseResult.success(instanceService.queryList(pageDto));
    }

    /**
     * 查询流程实例详情
     */
    @GetMapping("queryDetailByProcessInstanceId")
    public ResponseResult<InstanceRecordVO> queryDetailByProcessInstanceId(String processInstanceId) {
        return ResponseResult.success(instanceService.queryDetailByWorkflowInstanceId(processInstanceId)) ;
    }

    /**
     * 查询抄送我的流程实例
     */
    @SneakyThrows
    @PostMapping("queryMineCCProcessInstance")
    public ResponseResult<Page<InstanceCopyVo>> queryMineCCProcessInstance(@RequestBody DataQueryVO pageDto) {
        return ResponseResult.success(instanceUserCopyService.queryMineCCProcessInstance(pageDto));
    }


    /**
     * 查询进行中的任务
     */
    @SneakyThrows
    @PostMapping("queryTaskListInProgress/{processInstanceId}")
    public ResponseResult<List<TaskDto>> queryTaskListInProgress(@PathVariable String processInstanceId) {
        return ResponseResult.success(instanceService.queryTaskListInProgress(processInstanceId));
    }
}
